package com.example.myfragmenttest;

import com.example.myfragmenttest.Fragment1.OnFragListener;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends FragmentActivity implements OnFragListener{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
       
        
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
    
    @Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		
		
	}

	public void onClick2(View view) {
		System.out.println(11);
	}

	public void onButtonClick() {
		// TODO Auto-generated method stub
		System.out.println("onButtonClick"+this.getClass().toString());
		Fragment2 fragment2=(Fragment2) getSupportFragmentManager().findFragmentById(R.id.fragment2);
		if (fragment2!=null) {
			fragment2.changetext(String.valueOf(System.currentTimeMillis()));
		}else {
			
		}
		
		
	}

	public void onButOther() {
		// TODO Auto-generated method stub
		System.out.println("onButOther");
		
		
		Fragment3 fragment3=new Fragment3();
		FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
		
		//transaction.remove(fragment2);
		
		transaction.replace(R.id.fragment2, fragment3);
		transaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
		//transaction.addToBackStack(null);
		transaction.commit();	
			
			

		
		
		
		
		
	}

	public void onButOther3() {
		// TODO Auto-generated method stub
		Fragment1 fragment1=new Fragment1();
		FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.fragment2, fragment1);
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
		transaction.commit();
		
		
		
	}
    
}
